package com.huang.core.util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DBSessionUtil {
	private static SqlSession _session;
	private static String resource = "mybatis/mybatis.cfg.xml";

	public static SqlSession getDBSesstion() throws IOException {
		if (_session == null) {
			Reader reader = Resources.getResourceAsReader(resource);
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder()
					.build(reader);
			_session = sessionFactory.openSession();
		}
		return _session;
	}
}
